﻿Imports System
Imports System.Collections.Generic
Imports System.ServiceModel
Imports ATS.Business.Components
Imports ATS.Business.Entities
Imports System.IdentityModel.Selectors
Imports System.IdentityModel.Tokens
Imports System.ServiceModel.DomainServices.Server


'Imports ATS.Services.Contracts

' NOTE: You can use the "Rename" command on the context menu to change the class name "Service1" in both code and config file together.
Public Class AssetService
    Implements IAssetService


#Region "Assets"
    Public Function ListActiveAssets() As MainAssetsTable Implements IAssetService.ListActiveAssets
        Try
            Dim bc As New AssetComponent()
            Return bc.ReadMainAssetDetails("d")
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try

    End Function

    Public Function CreateAsset(_AssetDetails As MainAssetsTable) As MainAssetsTable Implements IAssetService.CreateAsset
        Try
            Dim cc As New AssetComponent()
            Return cc.CreateAsset(_AssetDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetAssetDetails(_searchAsset As String) As MainAssetsTable Implements IAssetService.GetAssetDetails
        Try
            Dim cc As New AssetComponent()
            Return cc.ReadMainAssetDetails(_searchAsset)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetAllAssets() As List(Of MainAssetsTable) Implements IAssetService.GetAllAssets
        Try
            Dim cc As New AssetComponent()
            Return cc.GetAllAssets()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function UpdateAssetDetails(_AssetDetails As MainAssetsTable) As MainAssetsTable Implements IAssetService.UpdateAssetDetails
        Try
            Dim cc As New AssetComponent()
            Return cc.UpdateAsset(_AssetDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Sub DeleteAsset(_AssetDetails As MainAssetsTable) Implements IAssetService.DeleteAsset
        Try
            Dim cc As New AssetComponent()
            cc.DeleteMainAsset(_AssetDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Sub
#End Region

#Region "Users"
    Public Function AuthenticateUser(ByVal username As String, ByVal password As String) As AuthenticationResult Implements IAssetService.AuthenticateUser
        Try
            Dim authenticateResult As New AuthenticateComponent
            Return authenticateResult.AuthenticateUser(username, password)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function VerifyHash(ByVal encryptedPassword As String, ByVal hash As String, ByVal salt As String) As Boolean Implements IAssetService.VerifyHash
        Try
            Dim hashVerified As New AuthenticateComponent
            Return hashVerified.VerifyHash(encryptedPassword, hash, salt)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetUserDetails(ByVal username As String) As UserTable Implements IAssetService.GetUserDetails
        Try
            Dim userDetails As New UserTableComponent
            Return userDetails.ReadUserDetails(username)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function UpdatePassword(ByVal userdetail As UserTable) As UserTable Implements IAssetService.UpdatePassword
        Try
            Dim userDetails As New UserTableComponent
            Return userDetails.UpdatePassword(userdetail)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetAllUsers() As List(Of UserTable) Implements IAssetService.GetAllUsers
        Try
            Dim userDetails As New UserTableComponent
            Return userDetails.GetAllUsers
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function CreateNewUser(ByVal userdetail As UserTable) As UserTable Implements IAssetService.CreateNewUser
        Try
            Dim userDetails As New UserTableComponent
            Return userDetails.CreateUser(userdetail)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function UpdateUser(ByVal userdetail As UserTable) As UserTable Implements IAssetService.UpdateUser
        Try
            Dim userDetails As New UserTableComponent
            Return userDetails.UpdateUserDetails(userdetail)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function IObservableListGetAllUsers() As IObserveUserTable Implements IAssetService.IObservableListGetAllUsers
        Try
            Return IObserveUserTableComponent.GetList
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Sub DeleteUser(ByVal userdetail As UserTable) Implements IAssetService.DeleteUser
        Try
            Dim userDetails As New UserTableComponent
            userDetails.DeleteUser(userdetail)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Sub

    Public Function UserExists(ByVal username As String) As Boolean Implements IAssetService.UserExists
        Try
            Dim userDetails As New UserTableComponent
            Return userDetails.UserExists(username)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function
#End Region

#Region "Password Configuration"
    Public Function AccountPolicyValues() As admPasswordConfig Implements IAssetService.AccountPolicyValues
        Try
            Dim accountPolicyData As New AccountPolicyComponent
            Return accountPolicyData.AccountPolicyValues
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function UpdateAccountPolicy(admPasswordConfigValues As admPasswordConfig) As admPasswordConfig Implements IAssetService.UpdateAccountPolicy
        Try
            Dim accountPolicyData As New AccountPolicyComponent
            Return accountPolicyData.UpdateAccountPolicyValues(admPasswordConfigValues)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

#End Region

#Region "Company Detail"
    Public Function CreateNewCompanyDetail(ByVal companyDetails As CompanyDetail) As CompanyDetail Implements IAssetService.CreateNewCompanyDetail
        Try
            Dim companyDetail As New CompanyDetailComponent
            Return companyDetail.CreateCompanyDetail(companyDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function ReadCompanyDetail() As CompanyDetail Implements IAssetService.ReadCompanyDetail
        Try
            Dim companyDetail As New CompanyDetailComponent
            Return companyDetail.ReadCompanyDetail()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function UpdateCompanyDetail(ByVal companyDetails As CompanyDetail) As CompanyDetail Implements IAssetService.UpdateCompanyDetail
        Try
            Dim companyDetail As New CompanyDetailComponent
            Return companyDetail.UpdateCompanyDetail(companyDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function
#End Region

#Region "RFID Scan History"
    Public Sub CreateRFIDScanHistory(_RFIDScanHistory As RFIDScanHistory, Optional _CreateAssetData As Boolean = False, Optional _CreatedBy As String = Nothing) Implements IAssetService.CreateRFIDScanHistory
        Try
            Dim rfidScanHistory As New RFIDScanHistoryComponent
            rfidScanHistory.CreateNewScanHistory(_RFIDScanHistory, _CreateAssetData, _CreatedBy)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Sub

    Public Function ReadRFIDScanHistoryByRFIDNumber(_RFIDNumber As String, Optional _RFIDScanDate As DateTime = Nothing) As List(Of RFIDScanHistory) Implements IAssetService.ReadRFIDScanHistoryByRFIDNumber

        Try
            Dim rfidScanHistory As New RFIDScanHistoryComponent
            Return rfidScanHistory.ReadRFIDScanHistoryByRFIDNumber(_RFIDNumber, _RFIDScanDate)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function ReadRFIDScanHistoryByScanDate(_scanDateFrom As Date, _scanDateTo As Date) As List(Of RFIDScanHistory) Implements IAssetService.ReadRFIDScanHistoryByScanDate
        Try
            Dim rfidScanHistory As New RFIDScanHistoryComponent
            Return rfidScanHistory.ReadRFIDScanHistoryByScanDate(_scanDateFrom, _scanDateTo)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function
#End Region

#Region "Category"
    Public Function CreateCategory(_category As Category) As Category Implements IAssetService.CreateCategory
        Try
            Dim cc As New CategoryComponent()
            Return cc.CreateCategory(_category)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function ReadCategory(_category As String) As Category Implements IAssetService.ReadCategory
        Try
            Dim cc As New CategoryComponent()
            Return cc.ReadCategory(_category)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function ReadAllCategories() As List(Of Category) Implements IAssetService.ReadAllCategories
        Try
            Dim cc As New CategoryComponent()
            Return cc.ReadAllCategories()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetAllCategoryClass() As List(Of String) Implements IAssetService.GetAllCategoryClass
        Try
            Dim cc As New CategoryComponent()
            Return cc.GetAssetClassList()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function UpdateCategoryRecord(_category As Category) As Category Implements IAssetService.UpdateCategoryRecord
        Try
            Dim cc As New CategoryComponent()
            Return cc.UpdateCategoryRecord(_category)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Sub DeleteCategory(_category As Category) Implements IAssetService.DeleteCategory
        Try
            Dim cc As New CategoryComponent()
            cc.DeleteCategory(_category)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Sub
#End Region

#Region "Location"
    Public Function CreateLocation(_location As Location) As Location Implements IAssetService.CreateLocation
        Try
            Dim cc As New LocationComponent()
            Return cc.CreateLocation(_location)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function ReadLocation(_location As String) As Location Implements IAssetService.ReadLocation
        Try
            Dim cc As New LocationComponent()
            Return cc.ReadLocation(_location)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function ReadAllLocations() As List(Of Location) Implements IAssetService.ReadAllLocations
        Try
            Dim cc As New LocationComponent()
            Return cc.ReadAllLocations()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Function UpdateLocationRecord(_location As Location) As Location Implements IAssetService.UpdateLocationRecord
        Try
            Dim cc As New LocationComponent()
            Return cc.UpdateLocationRecord(_location)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Sub DeleteLocation(_location As Location) Implements IAssetService.DeleteLocation
        Try
            Dim cc As New LocationComponent()
            cc.DeleteLocation(_location)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Sub
#End Region

#Region "Person"
    Public Function CreatePerson(_personDetails As Person) As Person Implements IAssetService.CreatePerson
        Try
            Dim cc As New PersonComponent()
            Return cc.CreatePerson(_personDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetPersonDetails(_searchPerson As String) As Person Implements IAssetService.GetPersonDetails
        Try
            Dim cc As New PersonComponent()
            Return cc.ReadPersonDetails(_searchPerson)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetAllPersons() As List(Of Person) Implements IAssetService.GetAllPersons
        Try
            Dim cc As New PersonComponent()
            Return cc.GetAllPersons()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Function UpdatePersonDetails(_personDetails As Person) As Person Implements IAssetService.UpdatePersonDetails
        Try
            Dim cc As New PersonComponent()
            Return cc.UpdatePerson(_personDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Sub DeletePerson(_personDetails As Person) Implements IAssetService.DeletePerson
        Try
            Dim cc As New PersonComponent()
            cc.DeletePerson(_personDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Sub
#End Region

#Region "Department"
    Public Function CreateDepartment(_DepartmentDetails As Department) As Department Implements IAssetService.CreateDepartment
        Try
            Dim cc As New DepartmentComponent()
            Return cc.CreateDepartment(_DepartmentDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetDepartmentDetails(_searchDepartment As String) As Department Implements IAssetService.GetDepartmentDetails
        Try
            Dim cc As New DepartmentComponent()
            Return cc.ReadDepartmentDetails(_searchDepartment)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetAllDepartments() As List(Of Department) Implements IAssetService.GetAllDepartments
        Try
            Dim cc As New DepartmentComponent()
            Return cc.GetAllDepartments()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function

    Public Function GetDepartmentList() As List(Of String) Implements IAssetService.GetDepartmentList
        Try
            Dim cc As New DepartmentComponent()
            Return cc.GetDepartmentList()
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Function UpdateDepartmentDetails(_DepartmentDetails As Department) As Department Implements IAssetService.UpdateDepartmentDetails
        Try
            Dim cc As New DepartmentComponent()
            Return cc.UpdateDepartment(_DepartmentDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function


    Public Sub DeleteDepartment(_DepartmentDetails As Department) Implements IAssetService.DeleteDepartment
        Try
            Dim cc As New DepartmentComponent()
            cc.DeleteDepartment(_DepartmentDetails)
        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Sub
#End Region

#Region "Disposal Methods List"
    Public Function GetDisposalMethods() As List(Of String) Implements IAssetService.GetDisposalMethods
        Try
            Dim dl As New DisposedAssetComponent()
            Return dl.GetDisposalMethods()

        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function
#End Region

#Region "Depreciation List"
    Public Function DepreciationList() As List(Of DepreciationClass) Implements IAssetService.DepreciationList
        Try
            Dim dl As New DepreciationComponent()
            Return dl.DepreciationList()

        Catch ex As Exception
            Throw New FaultException(Of ProcessExecutionFault)(New ProcessExecutionFault(), ex.Message)
        End Try
    End Function
#End Region

End Class



